﻿using Xtensive.Orm;

namespace NumericFields.Model
{
    /*
     * Some database servers allow to specify precision and scale parameters for numeric columns.
     * For example, in SQL Server precision can vary from 1 to 38 which influence how much room a numeric column
     * takes in data row. Scale is responsible for how many digits are stored to the right of the decimal point.
     * 
     * It might be a good practice to specify parameters of decimal fields. e.g. for a field that stores Price values
     * it is enough to store just 2 digits to the right of decimal point. If you don't expect to deal with prices more than 
     * $9,999,999.99 then Precision parameter can also be set to 9 digits. This will reduce the number of storage bytes required
     * for that column from 9 to 5 for each data row.
     */
    [HierarchyRoot]
    public class Book : Entity
    {
        [Field, Key]
        public int Id { get; set; }

        [Field]
        public string Title { get; set; }

        // Setting Scale to store 2 digits to the right of the decimal point for cents
        [Field(Precision = 9, Scale = 2)]
        public decimal Price { get; set; }

        public Book(Session session) :
            base(session) {}
    }
}